﻿namespace ServiceModel.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Witcraft.Halcyone.ServiceModel;

    [TestClass]
    public class StringExtensionTests
    {
        #region Public Methods

        [TestMethod]
        public void GetUriPatternParameterNames()
        {
            string uriPattern = ("/{id}/{date}/{dbl}");
            var result = uriPattern.GetUriPatternParameterNames();
            Assert.IsTrue(result.Contains("id"));
            Assert.IsTrue(result.Contains("date"));
            Assert.IsTrue(result.Contains("dbl"));
        }

        [TestMethod]
        public void InsertUriParameters()
        {
            string format = ("/{id}/{date}/{dbl}");
            string result = format.InsertUriParameters(
                new Dictionary<string, string>
                    {
                        {"date", new DateTime(2009, 3, 1).ToString("MM-dd-yyyy", CultureInfo.InvariantCulture)},
                        {"id", 3.ToString(CultureInfo.InvariantCulture)},
                        {"dbl", 3.454.ToString(CultureInfo.InvariantCulture)}
                    });

            Assert.AreEqual("/3/03-01-2009/3.454", result);
        }

        [TestMethod]
        public void RemoveRedundantSlashes()
        {
            string strWithSlashes = (@"//\\\{id}//{d}\\");

            Assert.AreEqual("/{id}/{d}/", strWithSlashes.RemoveRedundantSlashes());
        }

        #endregion
    }
}